﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pandora
{
    class XmlRPC
    {
        public XmlRPC() { }

        public dynamic XmlRPC_Value(dynamic v)
        {
            dynamic ret;

            if (v is string)
            {
                ret = "<value><string>%s</string></value>";//%escape(v)
            }

            else if (v) //true
            {
                ret = "<value><boolean>1</boolean></value>";
            }

            else if (!v) //false
            {
                ret = "<value><boolean>0</boolean></value>";
            }

            else if (v is int) //false
            {
                ret = string.Format("<value><int>{0}</int></value>",v);
            }

            else if (v is dynamic[]) //false
            {
                ret = string.Format("<value><int>{0}</int></value>", v); //"<value><array><data>%s</data></array></value>"%("".join([xmlrpc_value(i) for i in v]))
            }

            else
            {
                 throw new ArgumentException(string.Format("Can't encode {0} of type {1} to XMLRPC",v, typeof(v)));//raise ValueError("Can't encode %s of type %s to XMLRPC"%(v, type(v)))
            }

            return ret;
        }

        public string XmlRPC_MakeCall(string method, string args) //i think method and args are type string
        {
            args = "implement"; //"".join(["<param>%s</param>"%xmlrpc_value(i) for i in args])
            return string.Format(@"<?xml version=\""1.0\""?><methodCall><methodName>{0}</methodName><params>{0}</params></methodCall>",method, args);
        }

        public string XmlRPC_ParseValue(string tree)
        {
            string b = tree.
        }

    }
}
